package top.dbpanda.cmsjpa.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author 20018954
 */
@Data
@Entity
@Table(name = "user")
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
public class UserEntity implements Serializable {

    @Id
    @GeneratedValue(generator = "id")
    @GenericGenerator(name = "id", strategy = "top.dbpanda.cmsjpa.config.SnowFlakeIdGenerator")
    private Long id;

    @Column(name = "account", nullable = false, length = 50)
    private String account;

    @Column(name = "passwd", nullable = false, length = 50)
    private String passwd;

    @Column(name = "salt", nullable = false, updatable = false, length = 10)
    private String salt;

    @Column(name = "nick_name")
    private String nickName;

    @Column(name = "is_deleted")
    private Integer deleted;

    @Column(name = "version")
    @Version
    private Integer version;

    @Column(name = "create_by")
    @CreatedBy
    private Long createBy;

    @Column(name = "update_by")
    @LastModifiedBy
    private Long updateBy;

    /**
     * &#064;CreatedDate  自动填充创建时间
     */
    @Column(name = "create_time", updatable = false)
    @CreatedDate
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss ", timezone = "GMT+8")
    private Date createTime;

    /**
     * &#064;LastModifiedDate  自动填充修改时间
     */
    @Column(name = "update_time")
    @LastModifiedDate
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss ", timezone = "GMT+8")
    private Date updateTime;

}